//
//  RWOrderDetailHeaderView.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/18.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "RWOrderDetailHeaderView.h"

#define BottomAddressHeigth 70

@interface RWOrderDetailHeaderView ()

@property (nonatomic, copy) RWMyOrderDetailModel *myOrderDetailModel;
@property (nonatomic, copy) RWAddressModel *addressModel;

@end

@implementation RWOrderDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setOrderDetailHeaderUI];
    }
    return self;
}


- (void)loadDataWithOrderModel:(RWMyOrderDetailModel *)orderModel andAddressModel:(RWAddressModel *)addrModel{
    
    _myOrderDetailModel = [RWMyOrderDetailModel mj_objectWithKeyValues:orderModel];
    _addressModel = [RWAddressModel mj_objectWithKeyValues:addrModel];
    [self configDatas];
    
}

- (void)configDatas{
    
    _snLab.text = _myOrderDetailModel.order_sn;
    
    //_stateLab.text = _myOrderDetailModel.order_state;
    _stateLab.text = [self getOrderStateValue:_myOrderDetailModel.order_state];
    _timeLab.text = _myOrderDetailModel.add_time;
    _shippingNameLab.text = _myOrderDetailModel.shipping_name;
    _shippingCodeLab.text = _myOrderDetailModel.shipping_code;
    _wineConsumeLab.text = _myOrderDetailModel.cost_balance;
    _sumConsumeLab.text = _myOrderDetailModel.sum;
    
    _nameLab.text = [NSString stringWithFormat:@"%@ %@", _addressModel.true_name, _addressModel.mob_phone];
    //_addressLab.text = _addressModel.address;
    if (_addressModel.area && _addressModel.address) {
        _addressLab.text = [NSString stringWithFormat:@"%@ %@",_addressModel.area,_addressModel.address];
    }else{
        _addressLab.text = [NSString stringWithFormat:@"%@",_addressModel.address];
    }
    
}

- (NSString *)getOrderStateValue:(NSString *)orderState{
    int state = [orderState intValue];
    NSString *orderStateStr = @"";
    switch (state) {
        case 0:
        {
            orderStateStr = @"已取消";
        }
            break;
        case 10:
        {
            orderStateStr = @"未付款";
        }
            break;
        case 20:
        {
            orderStateStr = @"已付款";
        }
            break;
        case 30:
        {
            orderStateStr = @"已发货";
        }
            break;
        case 40:
        {
            orderStateStr = @"已收货";
        }
            break;
        default:
            orderStateStr = @"未付款";
            break;
    }
    
    return orderStateStr;
}
- (void)setOrderDetailHeaderUI{
    
    WeakSelf(ws);

    NSArray *titles = @[@"订单编号：", @"订单状态：", @"订单时间：", @"物流公司：", @"物流单号：", @"酒券消费：", @"余额消费：", @"合计消费："];
    
    for (int i=0; i<titles.count; i++) {
        
        UILabel *titleLab = [[UILabel alloc] init];
        [self addSubview:titleLab];
        titleLab.text = titles[i];
        titleLab.textColor = [FTYColor blackColor];
        titleLab.font = FTY_FONTTSIZE(15);
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10*FTY_HEIGHT_BASE + (10 + 25)*FTY_HEIGHT_BASE*i);
            make.left.mas_equalTo(10.*FTY_WIDTH_BASE);
            make.width.mas_equalTo(80.*FTY_WIDTH_BASE);
            make.height.mas_equalTo(25.*FTY_HEIGHT_BASE);
        }];
        
        UILabel *contentLab = [[UILabel alloc] init];
        [self addSubview:contentLab];
        contentLab.textColor = [FTYColor grayColor];
        contentLab.font = FTY_FONTTSIZE(15);
        [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10*FTY_HEIGHT_BASE + (10 + 25)*FTY_HEIGHT_BASE*i);
            make.left.mas_equalTo(titleLab.mas_right).offset(10.*FTY_WIDTH_BASE);
            make.right.mas_offset(-10.*FTY_WIDTH_BASE);
            make.height.mas_equalTo(25.*FTY_HEIGHT_BASE);
        }];
        
        switch (i) {
            case 0:
                _snLab = contentLab;
                break;
            case 1:
                _stateLab = contentLab;
                break;
            case 2:
                _timeLab = contentLab;
                break;
            case 3:
                _shippingNameLab = contentLab;
                break;
            case 4:
                _shippingCodeLab = contentLab;
                break;
            case 5:
                _wineConsumeLab = contentLab;
                break;
            case 6:
                _balanceLab = contentLab;
                break;
            case 7:
                _sumConsumeLab = contentLab;
                break;
                
            default:
                break;
        }
    }
    
    CGFloat midLineY = CGRectGetHeight(ws.frame) - BottomAddressHeigth*FTY_HEIGHT_BASE;
    
    //分割线
    UIView *line = [[UIView alloc] init];
    [self addSubview:line];
    line.backgroundColor = [UIColor grayColor];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(midLineY);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(.5*FTY_HEIGHT_BASE);
    }];
    
    //收货人信息
    UIButton *positionIcon = [[UIButton alloc] init];
    [self addSubview:positionIcon];
    [positionIcon setImage:[UIImage imageNamed:@"position_icon"] forState:UIControlStateNormal];
    [positionIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(midLineY + 20.*FTY_HEIGHT_BASE);
        make.left.mas_offset(10.*FTY_WIDTH_BASE);
        make.width.height.mas_offset(25.*FTY_WIDTH_BASE);
    }];
        
    UILabel *nameLab = [[UILabel alloc] init];
    [self addSubview:nameLab];
    nameLab.textColor = [FTYColor blackColor];
    nameLab.font = FTY_FONTTSIZE(14);
    [nameLab sizeToFit];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(midLineY + 15.*FTY_HEIGHT_BASE);
        make.left.mas_equalTo(positionIcon.mas_right).offset(10.*FTY_WIDTH_BASE);
        make.right.mas_equalTo(-60.*FTY_WIDTH_BASE);
    }];
    _nameLab = nameLab;
    
    UILabel *addressLab = [[UILabel alloc] init];
    [self addSubview:addressLab];
    addressLab.textColor = [FTYColor blackColor];
    addressLab.font = FTY_FONTTSIZE(14);
    addressLab.numberOfLines = 2;
    [addressLab sizeToFit];
    [addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.top.mas_equalTo(nameLab.mas_bottom).offset(10.*FTY_HEIGHT_BASE);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-5.*FTY_HEIGHT_BASE);
        make.left.mas_equalTo(nameLab.mas_left);
        make.right.mas_equalTo(nameLab.mas_right);
    }];
    _addressLab = addressLab;
}

@end
